#include "../ex4/fileperf.hh"

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <string>

#include <cstdio>

using namespace std;

int main(int argc, char** argv)
{
	uint block_size, pointer_size, maximal_size;
	storageType type;


	if ( 5 != argc )
	{
		cerr<< "Usage: " << argv[0] <<
				" <block size> <pointer size> <maximal size> <FAT/iNode>" << endl;
		return 1;
	}


	outputStruct out;

	block_size = atoi(argv[1]);
	pointer_size = atoi(argv[2]);
	maximal_size = atoi(argv[3]);

	if ( ! block_size || ! pointer_size || ! maximal_size )
	{
		cerr<< "Error: one of the arguments was invalid!" << endl;
	}

	if ( ! strcmp(argv[4], "FAT")  )
	{
		type = FS_LINKED_LIST;
	}
	else if ( ! strcmp(argv[4], "iNode") )
	{
		type = FS_INODE;
	}
	else
	{
		cerr << "Error: unknown FS type" << endl;
		return 1;
	}

	cout << "Start receive files' sizes " << endl;
	vector<uint> sizes;
	string line;

	do
	{
		cin >> line;
		if ( ! cin )
		{
			break;
		}
		sizes.push_back( atoi( line.c_str() ) );
	}
	while ( 1 );

	cin.clear();

	int res = fileSystemPerformance (block_size,
									 pointer_size,
									 maximal_size,
									 type,
									 sizes,
									 & out);

	if ( ! res )
	{
		printf("space: %ld\n", out.space);
		printf("Avg access num: %f\n", out.averageAccessNum);
	}

	return res;
}
